# -*- coding: utf-8 -*-
import numpy as np
import pandas as pd

if __name__ == '__main__':
    dict_obj = {
        'key1':['a', 'b', 'a', 'b','a', 'b', 'a', 'a'],
        'key2':['one', 'one', 'two','three','two','two','one','three'],
        'data1':np.random.rand(8),
        'data2':np.random.rand(8)
    }
    frame = pd.DataFrame(dict_obj)
    print frame
    print frame.groupby('key1')
    print type(frame.groupby('key1'))
    print frame.groupby('key1').size()
    print frame.groupby(frame['key1']).size()
    print frame.groupby([frame['key1'],frame['key2']]).size()
    print frame.groupby(['key1','key2']).size()
    print "============================================="
    groupby = frame.groupby('key1')
    for groupby_name, groupby_value in groupby:
        print groupby_name
        print "-------------------"
        print groupby_value
        print ",,,,,,,,,,,,,,,,,,,,,,"
    print "======================转化为list============================="
    print list(groupby)
    print len(list((groupby)))
    print "===========转化为字典========================================"
    print dict(list(groupby))
    d = dict(list(groupby))
    print "++++++++++++++++="
    print d['a']
    print type(d['a'])